package serverApp.threads;

public class SMSClient implements Runnable {

	private Thread myThread = null;

	private String recipient = null;
	private String message = null;

	public int status = -1;
	public long messageNo = -1;

	public int sendMessage(String recipient, String message) {
		this.recipient = recipient;
		this.message = message;
		myThread = new Thread(this);
		myThread.start();
		return status;
	}

	public void run() {

		Sender aSender = new Sender(recipient, message);

		try {
			// отправить сообщение
			aSender.send();

			// ждем статуса: 0 == OK, -2 == истечение времени, -1 == другие
			// ошибки
			while (aSender.status == -1) {
				myThread.sleep(1000);
			}
			if (aSender.status == 0)
				messageNo = aSender.messageNo;

		} catch (Exception e) {

			e.printStackTrace();

		}

		this.status = aSender.status;

		aSender = null;

	}
}